import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiRadioPage(Base):
    """
    语音训练导航电台页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.radio_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("ivHome"))

        # 左侧的返回键
        self.radio_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format('ivBack'))

        # 本地电台标题
        self.radio_local_title_text = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("btn_native"))

        # 在线电台标题
        self.radio_online_title_text = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("btn_online"))

        # fm/am开关
        self.radio_fm_select_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("rb_fm"))

        # fm/am开关
        self.radio_am_select_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("rb_am"))

        # 确认按钮
        self.radio_sure_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("btn_ok"))

        # 快退按钮
        self.radio_rewind_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("bt_skip_previous"))

        # 快进按钮
        self.radio_fast_forward_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("bt_skip_next"))

        # 当前频道
        self.radio_now_channel_text = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("tv_channel_frequency"))

        # 减频道
        self.radio_minus_channel_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("bt_reduce"))

        # 加频道
        self.radio_add_channel_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("bt_add"))

        # 频幅
        self.radio_frequency_icon = (By.XPATH, Yomi.frequency_icon.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.radio_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.radio_home_btn)

    def get_local_title(self):
        """
        获取本地电台标题

        :return:获取元素
        """
        return self.find_element_o(self.radio_local_title_text)

    def get_online_title(self):
        """
        获取在线电台标题

        :return:获取元素
        """
        return self.find_element_o(self.radio_online_title_text)

    def get_fm_select(self):
        """
        获取fm切换tab

        :return:获取元素
        """
        return self.find_element_o(self.radio_fm_select_btn)

    def get_am_select(self):
        """
        获取fm切换tab

        :return:获取元素
        """
        return self.find_element_o(self.radio_am_select_btn)

    def click_local_title(self):
        """
        点击本地电台

        :return:None
        """
        self.click_element(self.radio_local_title_text)

    def click_online_title(self):
        """
        点击在线电台

        :return:None
        """
        self.click_element(self.radio_online_title_text)

    def click_fm_select(self):
        """
        点击fm按钮

        :return:None
        """
        self.click_element(self.radio_fm_select_btn)

    def click_am_select(self):
        """
        点击am按钮

        :return:None
        """
        self.click_element(self.radio_am_select_btn)

    def click_sure(self):
        """
        点击确认按钮

        :return:None
        """
        self.click_element(self.radio_sure_btn)

    def click_rewind(self):
        """
        点击快退按钮

        :return:None
        """
        self.click_element(self.radio_rewind_btn)

    def click_fast_forward(self):
        """
        点击快进按钮

        :return:None
        """
        self.click_element(self.radio_fast_forward_btn)

    def click_minus_channel(self):
        """
        点击减频道按钮

        :return:None
        """
        self.click_element(self.radio_minus_channel_btn)

    def click_add_channel(self):
        """
        点击加频道按钮

        :return:None
        """
        self.click_element(self.radio_add_channel_btn)

    def get_now_channel(self):
        """
        获取当前频道

        :return:获取元素
        """
        return self.find_element_o(self.radio_now_channel_text)

    def get_frequency(self, index=4):
        """
        获取频幅图标

        :return:获取元素
        """
        self.radio_frequency_icon = (By.XPATH, Yomi.frequency_icon.format(index))
        return self.find_element_o(self.radio_frequency_icon)

    def swipe_radio_list(self):
        """
        滑动城市列表

        :return:None
        """
        self.swipe_o(location=(1045, 1545, 500, 500), direction='left')

    def is_display_yomi_radio(self):
        """
        查看是否进入语音训练电台
        :return:
        """
        return self.is_display(self.radio_local_title_text)
